#pragma once

#include "znx_defs.h"

///////////// crc16 /////////////////
static inline uint32_t
znx_crc16(const u_char *data, size_t len) {
    uint32_t  sum;

    for (sum = 0; len; len--) {
        /*
         * gcc 2.95.2 x86 and icc 7.1.006 compile
         * that operator into the single "rol" opcode,
         * msvc 6.0sp2 compiles it into four opcodes.
         */
        sum = sum >> 1 | sum << 31;
        sum += *data++;
    }

    return sum;
}


//////////////// crc32 ///////////////
#define znx_crc32_init(crc)                                          \
    crc = 0xffffffff

void
znx_crc32_update(uint32_t *crc, const u_char *p, size_t len);

#define znx_crc32_final(crc)                                         \
    crc ^= 0xffffffff

uint32_t
znx_crc32_short(const u_char *p, size_t len);

uint32_t
znx_crc32_long(const u_char *p, size_t len);


uint32_t
znx_crc32_short_lower(const u_char *p, size_t len);

uint32_t
znx_crc32_long_lower(const u_char *p, size_t len);

